package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.AxisType;
import com.db.williamchart.data.Paddings;

public class MeasureBarChartPaddings {

    public Paddings invoke(AxisType axisType,Float labelsHeight,Float longestLabelWidth,Float labelsPaddingToInnerChart){
        return measurePaddingsX(axisType, labelsHeight, labelsPaddingToInnerChart).mergeWith(
                measurePaddingsY(axisType, labelsHeight, longestLabelWidth, labelsPaddingToInnerChart)
        );
    }
    private Paddings measurePaddingsX(AxisType axisType,Float labelsHeight,Float labelsPaddingToInnerChart){
        return new Paddings(0F, 0F, 0f, axisType.shouldDisplayAxisX() ? labelsHeight + labelsPaddingToInnerChart : 0F);
    }
    private Paddings measurePaddingsY(AxisType axisType,Float labelsHeight,Float longestLabelWidth,Float labelsPaddingToInnerChart){
        if (!axisType.shouldDisplayAxisY()){
            return new Paddings(0f,0f,0f,0f);
        }
        return new Paddings(longestLabelWidth + labelsPaddingToInnerChart, labelsHeight / 2, 0f, labelsHeight / 2);
    }
}
